const tipsList = [
    {
        label: "全选",
        value: "Ctrl + A"
    },
    {
        label: "复制",
        value: "Ctrl + C"
    },
    {
        label: "粘贴",
        value: "Ctrl + V"
    },
    {
        label: "撤销",
        value: "Ctrl + Z"
    },
    {
        label: "重做",
        value: "Ctrl + Y"
    },
    {
        label: "搜索",
        value: "Ctrl + F"
    },
    {
        label: "打开新的Tab页",
        value: "Ctrl + T"
    },
    {
        label: "保存",
        value: "Ctrl + S"
    },
    {
        label: "替换",
        value: "Ctrl + H"
    },

];
// 判断当前的点击的键是否是被允许使用的
export function isValidShortcuts(keyboard) {
    let flag = false;
    let str = "";
    if (keyboard.keyCode == 48) {
        // 数字0
        flag = true;
        str += "0";
    } else if (keyboard.keyCode >= 65 && keyboard.keyCode <= 90) {
        // 字母A-Z
        if (!keyboard.ctrlKey) {
            flag = true;
            str += keyboard.key.toLocaleUpperCase();
        } else if (keyboard.ctrlKey) {
            // Ctrl+B,I,M,Q可以用，其他都是电脑默认设置的
            const validCode = [66, 73, 77, 81]
            if (validCode.includes(keyboard.keyCode)) {
                flag = true;
                str += keyboard.key.toLocaleUpperCase();
            } else {
                flag = false;
                keyboard.preventDefault();
                keyboard.stopPropagation(); // 阻止事件冒泡
                console.log(
                    "Ctrl + " + keyboard.key.toLocaleUpperCase() + " 被阻止了，并且事件不会冒泡"
                );
            }
        } else if (keyboard.altKey) {
            if (keyboard.keyCode != 65) {
                flag = true;
                str += "A";
            } else {
                flag = false;
                keyboard.preventDefault();
                keyboard.stopPropagation(); // 阻止事件冒泡
                console.log(
                    "Alt + " + keyboard.key.toLocaleUpperCase() + " 被阻止了，并且事件不会冒泡"
                );
            }

        }
    } else if (
        keyboard.keyCode == 186 ||
        keyboard.keyCode == 188 ||
        keyboard.keyCode == 190 ||
        keyboard.keyCode == 191 ||
        (keyboard.keyCode >= 219 && keyboard.keyCode <= 222)
    ) {
        flag = true;
        // 特殊符号
        str +=
            keyboard.keyCode == 186
                ? ";"
                : keyboard.keyCode == 188
                    ? ","
                    : keyboard.keyCode == 190
                        ? "."
                        : keyboard.keyCode == 191
                            ? "/"
                            : keyboard.keyCode == 219
                                ? "["
                                : keyboard.keyCode == 220
                                    ? "\\"
                                    : keyboard.keyCode == 221
                                        ? "]"
                                        : "'";
    }
    return { flag, str }
}
// 当前快捷键组合方式不合法的提示内容
export function shortcutsTips(shortcuts) {
    let str = "";
    const occupy = tipsList.filter(item => item.value == shortcuts)[0];
    if (occupy) {
        str = occupy.label;
    }
    return str;
}
